﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SidebarStarted.Models;
using SidebarStarted.ViewModels.OpenCvSharp;
using System;
using System.Collections.ObjectModel;

namespace SidebarStarted.ViewModels;

public partial class MainWindowViewModel : ViewModelBase
{
    public MainWindowViewModel()
    {
        CurrentPage = new HomePageViewModel();
        IsPanelOpen = true;
    }

    /// <summary>
    /// 是否打开
    /// </summary>
    [ObservableProperty] private bool _isPanelOpen;

    /// <summary>
    /// 当前页面
    /// </summary>
    [ObservableProperty] private ViewModelBase _currentPage;

    /// <summary>
    /// 列表选择项
    /// </summary>
    [ObservableProperty] private MenuBar? _selectedListItem;

    /// <summary>
    /// 菜单内容
    /// </summary>
    public ObservableCollection<MenuBar> MenuBars { get; } = new()
    {
        new MenuBar("主页", typeof(HomePageViewModel), "HomeRegular"),
        new MenuBar("证件照换背景", typeof(IdentityPhotoPageViewModel), "ImageRegular"),
        new MenuBar("测试1", typeof(TestOnePageViewModel), "TextNumberFormatRegular"),
        new MenuBar("测试2", typeof(TestTwoPageViewModel), "ImageRegular")
    };

    [RelayCommand]
    private void TriggerPane()
    {
        IsPanelOpen = !IsPanelOpen;
    }

    partial void OnSelectedListItemChanged(MenuBar? value)
    {
        if (value is null)
            return;

        var instance = Activator.CreateInstance(value.ModelType);
        if (instance is null)
            return;

        CurrentPage = (ViewModelBase)instance;
    }
}